#! /bin/sh

mkdir -p out || exit 99

name=$( basename "$0" )
datafile="out/${name}.data"
dumpfile="out/${name}.dump"
resultfile="out/${name}.result"
expectfile="$srcdir/basic.expect"

ei_class=2
ei_data=1
e_machine=62
e_phoff=64
page_size=4096

echo "@phdr type=LOAD offset=$page_size memsz=$page_size" >"$datafile"
cat "$expectfile" >> "$datafile"

./mkelf "$dumpfile" <<EOF
$extraparam
ei_class = $ei_class
ei_data = $ei_data
e_machine = $e_machine
e_phoff = $e_phoff

DATA = $datafile
EOF
rc=$?
if [ $rc -ne 0 ]; then
    echo "Cannot create ELF file" >&2
    exit $rc
fi
echo "Created ELF dump: $dumpfile"

./dumpdata "$dumpfile" 0 4096 >"$resultfile"
rc=$?
if [ $rc -ne 0 ]; then
    echo "Cannot dump ELF data" >&2
    exit $rc
fi

if ! diff "$expectfile" "$resultfile"; then
    echo "Results do not match" >&2
    exit 1
fi
